"""
Flask 应用启动入口
"""
import os
import sys
try:
    from server.app.app import create_app  # type: ignore
    from server.config.config import Config  # type: ignore
except ModuleNotFoundError:
    # 回退：允许直接在 server 目录执行
    sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
    from app.app import create_app  # type: ignore
    from config.config import Config  # type: ignore

# 创建应用实例
config_name = os.getenv('FLASK_ENV', 'development')
app = create_app(config_name)

if __name__ == '__main__':
    print(f"Starting Flask server on {Config.SERVER_HOST}:{Config.SERVER_PORT}")
    print(f"Environment: {config_name}")
    print(f"Database: {Config.SQLALCHEMY_DATABASE_URI}")
    print(f"Flowable: {Config.FLOWABLE_REST_URL}")
    
    app.run(
        host=Config.SERVER_HOST,
        port=Config.SERVER_PORT,
        debug=Config.DEBUG
    )
